package Controllers;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import Impl.BookServiceImpl;
import Impl.UserServiceImpl;

@Controller
public class BookDeleteController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	BookServiceImpl bookService;
	 @RequestMapping(value = "/bookdelete", method = {RequestMethod.POST,RequestMethod.GET})
		@ResponseBody
		public JSONObject userRegister(HttpServletRequest request) throws Exception {
		 	ApplicationContext applicationContext=(ApplicationContext)request.getSession().getServletContext().getAttribute("ctx");
	        bookService=(BookServiceImpl)applicationContext.getBean("BookServiceImpl");
			JSONObject obj = new JSONObject();
			String aString='"'+"";
			String abook=request.getParameter("bookid").replaceAll(aString, "");
			String bookid=abook;			
			System.out.println(bookid);
			bookService.deleteBook(bookid);
			obj.put("status", "OK");
			return obj;
		}
}
